package com.rockcent.mall.controller;

import com.rockcent.common.common.JsonResult;
import com.rockcent.common.common.PageResult;
import com.rockcent.common.common.RestDoing;
import com.rockcent.common.controller.BaseController;
import com.rockcent.common.domain.enumclass.Whether;
import com.rockcent.common.utils.RDateFormatUtils;
import com.rockcent.common.utils.RDateUtils;
import com.rockcent.mall.Routes;
import com.rockcent.mall.lib.domain.*;
import com.rockcent.mall.lib.domain.enumclass.*;
import com.rockcent.mall.lib.dto.*;
import com.rockcent.mall.lib.helper.*;
import com.rockcent.mall.lib.repository.*;
import com.rockcent.service.FundService;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.rockcent.mall.lib.domain.enumclass.MerchantOrderPathType.B2D2C;

/**
 * Created by DK on 16/10/31.
 *
 */
@RestController
public class MerchantVerifyController extends BaseController {
    private final Logger log = LoggerFactory.getLogger(MerchantVerifyController.class);

    @Autowired
    private BaseUserHelper userHelper;

    @Autowired
    private FundService fundService;

    @Autowired
    private VerificationHelper verificationHelper;

    @Autowired
    private MerchantOrderVerificationRepository merchantOrderVerificationRepository;

    @Autowired
    private MerchantStoreRepository merchantStoreRepository;

    @Autowired
    private CustomerProductOrderRepository customerProductOrderRepository;

    @Autowired
    private CustomerCouponWalletRepository customerCouponWalletRepository;

    @Autowired
    private MallOrderRepository mallOrderRepository;

    @Autowired
    private MerchantProductRepository merchantProductRepository;

    @Autowired
    private MerchantOrderRepository merchantOrderRepository;

    @Autowired
    private MerchantProductMerchantStoresRepository productMerchantStoresRepository;

    @Autowired
    private MerchantOrderItemRepository merchantOrderItemRepository;

    @Autowired
    private MerchantCouponRepository merchantCouponRepository;

    @Autowired
    private CouponMerchantStoreRepository couponMerchantStoreRepository;

    @Autowired
    private CustomerRepository customerRepository;

    @Autowired
    private OrderEventHelper orderEventHelper;

    @Autowired
    private ProductEventHelper productEventHelper;

    /**
     * @api {get} /merchant/order/verification/page 验证核销 产品核销记录
     * @apiGroup MERCHANT_VERIFY
     * @apiVersion 1.0.0
     * @apiHeader {String} userToken 用户token
     * @apiHeader {String} domain 请求域名
     *
     * @apiParam {Long} merchantStoreId  门店ID
     * @apiParam {Date} beginDate  开始时间
     * @apiParam {Date} endDate  结束时间
     * @apiParam {String} keyword  产品名称/编号
     * @apiParam {String=ALL("全部"), GOODS("商品"), SERVICE("服务")'} productType <cod>必传参数</cod> 产品类型
     *
     * @apiSuccess {Long} id 记录ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Long} productId 产品ID
     * @apiSuccess {String} customerName 客户名称
     * @apiSuccess {String} productLogo 产品LOGO
     * @apiSuccess {BigDecimal} productSellPrice 产品售价
     * @apiSuccess {String} merchantStoreName 核销门店名称
     * @apiSuccess {Long} verifyCount 核销数
     * @apiSuccess {String} productName 产品名称
     * @apiSuccess {String=SCAN("扫码核销"), KEY_IN("输码核销"), SELF_CONFIRM("自主核销")} verificationWay 核销方式
     * @apiSuccessExample {json} Success-Response:
     * {
     * "code": "1",
     * "desc": "成功",
     * "data": [
     * {
     *    "id": 3,
     *    "dateCreated": "2016-08-08 17:32:56",
     *    "lastUpdated": "2016-08-08 17:32:56",
     *    "productId": 2,
     *    "customerName": "张三",
     *    "productLogo": "http://uploads.rockcent.com/dev/product/promote/xxxx.jpg",",
     *    "productSellPrice": "23.23",
     *    "merchantStoreName": "珠江新车",
     *    "verifyCode": 2342234,
     *    "verifyCount": 2,
     *    "productName": "XXXXXX",
     *    "verificationWay": "SCAN"
     *  }
     *   ]
     * }
     */
    @RequestMapping(value = Routes.MERCHANT_ORDER_VERIFICATION_PAGE, method = RequestMethod.GET)
    private JsonResult merchantOrderVerificationPage(HttpServletRequest request, MerchantOrderVerificationDto dto) {
        UserInfoDto userInfoDto = userHelper.getSession(request);
        RestDoing doing = jsonResult -> {
            if (StringUtils.isBlank(dto.getProductType()) || !EnumUtils.isValidEnum(ProductType.class, dto.getProductType())) {
                jsonResult.remind("产品类型只允许ALL(\"全部\") GOODS(\"商品\"), SERVICE(\"服务\")",log);
                return;
            }
            if (StringUtils.isBlank(dto.getBeginDate())) {
                dto.setBeginDate(RDateFormatUtils.formatParseDatePattern(RDateUtils.beforeDate(30)));
                dto.setEndDate(RDateFormatUtils.formatParseDatePattern(new Date()));
            }
            PageResult<MerchantOrderVerificationDto> pageResult = merchantOrderVerificationRepository.findMerchantOrderVerificationPage(userInfoDto.merchant.getId(), dto.getMerchantStoreId(), dto.getKeyword(), dto.getProductType(), dto.getBeginDate(), dto.getEndDate(), this.getPage(dto.getPageNo(), dto.getPageSize()));
            pageResult.setUrl(Routes.MERCHANT_ORDER_VERIFICATION_PAGE);
            jsonResult.data = pageResult;
        };
        return doing.go(request, log);
    }

    /**
     * @api {get} /merchant/coupon/verification/page 验证核销 卡卷核销记录
     * @apiGroup MERCHANT_VERIFY
     * @apiVersion 1.0.0
     * @apiHeader {String} userToken 用户token
     * @apiHeader {String} domain 请求域名
     *
     * @apiParam {Long} merchantStoreId  门店ID
     * @apiParam {Date} beginDate  开始时间
     * @apiParam {Date} endDate  结束时间
     * @apiParam {String} keyword  产品名称/编号
     * @apiParam {String=ALL("全部"), VOUCHERS("抵用券"), DISCOUNT("折扣券")} couponType <cod>必传参数</cod> 卡卷类型
     *
     * @apiSuccess {Long} id 记录ID
     * @apiSuccess {Date} dateCreated 创建时间
     * @apiSuccess {Date} lastUpdated 更新时间
     * @apiSuccess {Long} couponId 产品ID
     * @apiSuccess {String} customerName 客户名称
     * @apiSuccess {String} logoUrl  卡卷LOGO
     * @apiSuccess {String=ALL("全部"), VOUCHERS("抵用券"), DISCOUNT("折扣券")} couponType  卡卷类型
     * @apiSuccess {BigDecimal} couponPrice 卡卷面值
     * @apiSuccess {String} merchantStoreName 核销门店名称
     * @apiSuccess {Long} useNum 核销数
     * @apiSuccess {double} faceValue 面值(抵用券)
     * @apiSuccess {double} discount 享受折扣(折扣券)
     * @apiSuccess {double} limitAmount 最低消费金额
     * @apiSuccess {String=SCAN("扫码核销"), KEY_IN("输码核销"), SELF_CONFIRM("自主核销")} verificationWay 核销方式
     *  @apiSuccessExample {json} Success-Response:
     * {
     * "code": "1",
     * "desc": "成功",
     * "data": [
     * {
     *    "id": 3,
     *    "dateCreated": "2016-08-08 17:32:56",
     *    "lastUpdated": "2016-08-08 17:32:56",
     *    "couponId": 2,
     *    "customerName": "张三",
     *    "logoUrl": "http://uploads.rockcent.com/dev/product/promote/xxxx.jpg",",
     *    "couponPrice": "23.23",
     *    "merchantStoreName": "珠江新车",
     *    "verifyCode": 2342234,
     *    "useNum": 2,
     *    "couponName": 2,
     *    "faceValue": 2,
     *    "discount": 2,
     *    "limitAmount": 123,
     *    "verificationWay": "SCAN"
     *  }
     *   ]
     * }
     */
    @RequestMapping(value = Routes.MERCHANT_COUPON_VERIFICATION_PAGE, method = RequestMethod.GET)
    private JsonResult merchantCouponVerificationPage(HttpServletRequest request, CustomerCouponWalletDto dto) {
        UserInfoDto userInfoDto = userHelper.getSession(request);
        RestDoing doing = jsonResult -> {
            if (StringUtils.isBlank(dto.getCouponType()) || !EnumUtils.isValidEnum(CouponType.class, dto.getCouponType())) {
                jsonResult.remind("卡卷类型只允许ALL(\"全部\"), VOUCHERS(\"抵用券\"), DISCOUNT(\"折扣券\")",log);
                return;
            }
            if (StringUtils.isBlank(dto.getBeginDate())) {
                dto.setBeginDate(RDateFormatUtils.formatParseDatePattern(RDateUtils.beforeDate(30)));
                dto.setEndDate(RDateFormatUtils.formatParseDatePattern(new Date()));
            }
            PageResult<CustomerCouponWalletDto> pageResult = customerCouponWalletRepository.findMerchantCouponVerificationPage(userInfoDto.merchant.getId(), dto.getMerchantStoreId(), dto.getCouponType(), dto.getKeyword(), dto.getBeginDate(), dto.getEndDate(), this.getPage(dto.getPageNo(), dto.getPageSize()));
            pageResult.setUrl(Routes.MERCHANT_COUPON_VERIFICATION_PAGE);
            jsonResult.data = pageResult;
        };
        return doing.go(request, log);
    }

    /**
     * @api {get} /merchant/verifier/page 验证核销 核销员管理
     * @apiGroup MERCHANT_VERIFY
     * @apiVersion 1.0.0
     * @apiHeader {String} userToken 用户token
     * @apiHeader {String} domain 请求域名
     *
     * @apiParam {Long} id  门店ID
     *
     * @apiSuccess {Long} id 门店id
     * @apiSuccess {String} number 门店编号
     * @apiSuccess {Long} verifierCount 核销员总数
     * @apiSuccess {String} name 店面名称
     * @apiSuccess {String} merchantName 商家名称
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     * "code": "1",
     * "desc": "成功",
     * "data": [
     * {
     *    "id": 3,
     *    "number": "002",
     *    "verifierCount": 3,
     *    "name": "水电费",
     *    "merchantName": "迪卡侬"
     *  }
     *   ]
     * }
     */
    @RequestMapping(value = Routes.MERCHANT_VERIFIER_PAGE, method = RequestMethod.GET)
    private JsonResult merchantVerifierPage(HttpServletRequest request, MerchantStoreDto dto) {
        UserInfoDto userInfoDto = userHelper.getSession(request);
        RestDoing doing = jsonResult -> {
            if (dto.getId() != null) {
                dto.setName(String.valueOf(dto.getId()));
            }
            PageResult<MerchantStoreDto> pageResult = merchantStoreRepository.
                    findByMerchantIdPage(userInfoDto.merchant.getId(), userInfoDto.mall.getId(), Whether.YES, dto.getStatus(), dto.getType(), Whether.NO, dto.getName(), dto.getLocationIds(), this.getPage(dto.getPageNo(), dto.getPageSize()));
            jsonResult.data = pageResult;
        };
        return doing.go(request, log);
    }


    /**
     * @api {put} /merchant/transmission/code/verify 验证核销 输码核销
     * @apiGroup MERCHANT_VERIFY
     * @apiVersion 1.0.0
     * @apiHeader {String} userToken 用户token
     * @apiHeader {String} domain 请求域名
     *
     * @apiParam {String} verifyCode  兑换码
     * @apiParam {String=COUPON("卡卷"), ORDER("产品")} verifyType  核销类型
     * @apiParam {Long} merchantStoreId  门店ID
     *
     * @apiSuccessExample {json} Success-Response:
     * {
     * "code": "1",
     * "desc": "成功"
     */
    @Transactional
    @RequestMapping(value = Routes.MERCHANT_TRANSMISSION_CODE_VERIFY, method = RequestMethod.PUT)
    private JsonResult merchantTransmissionCodeVerify(HttpServletRequest request, @RequestBody QrCodeDto dto) {
        UserInfoDto userInfoDto = userHelper.getSession(request);
        RestDoing doing = jsonResult -> {
            if (StringUtils.isNotBlank(dto.getVerifyType()) && !EnumUtils.isValidEnum(VerifyType.class, dto.getVerifyType())) {
                jsonResult.remind("核销类型 不能为空",log);
                return;
            }

            if (StringUtils.isBlank(dto.getVerifyCode())) {
                jsonResult.remind("兑换码 不能为空",log);
                return;
            }
            if (dto.getMerchantStoreId() == null) {
                jsonResult.remind("门店ID 不能为空",log);
                return;
            }

            MerchantStore merchantStore = merchantStoreRepository.findByIdAndMerchantIdAndMallIdAndIsDelete(dto.getMerchantStoreId(), userInfoDto.merchant.getId(), userInfoDto.mall.getId(), Whether.NO);
            if (merchantStore == null) {
                jsonResult.remind("门店不存在",log);
                return;
            }
            if (VerifyType.ORDER == VerifyType.valueOf(dto.getVerifyType())) {

                CustomerProductOrder customerProductOrder = customerProductOrderRepository.findByVerifyCodeAndStatusAndIsDelete(dto.getVerifyCode(), CustomerProductOrderStatus.TO_USE, Whether.NO);
                if (customerProductOrder == null) {
                    jsonResult.remind("兑换码 不存在",log);
                    return;
                }

                if (!Objects.equals(customerProductOrder.getMallId(), userInfoDto.mall.getId())) {
                    jsonResult.remind("兑换码 无效",log);
                    return;
                }

                if (!Objects.equals(customerProductOrder.getMerchantId(), userInfoDto.merchant.getId())) {
                    jsonResult.remind("兑换码 无效",log);
                    return;
                }

                MerchantOrder merchantOrder = merchantOrderRepository.findByOrderNumAndMallId(customerProductOrder.getMerchantOrderNum(), customerProductOrder.getMallId());

                MallOrder mallOrder = mallOrderRepository.findByOrderNumAndMallId(merchantOrder.getMallOrderNum(), userInfoDto.mall.getId());
                List<MerchantOrderItem> merchantOrderItemList = merchantOrderItemRepository.findByMerchantOrderIdAndMerchantId(merchantOrder.getId(), merchantOrder.getMerchantId());
                if (OrderType.SERVICE == merchantOrder.getOrderType()) {// 当订单类型为服务商品 merchant_order 、 merchant_order_item 一对一
                    MerchantOrderItem merchantOrderItem = null;
                    if (merchantOrderItemList.size() > 0) {
                        merchantOrderItem = merchantOrderItemList.get(0);
                    }
                    if (OrderStatus.WAIT_USE == merchantOrder.getStatus() || OrderStatus.PART_USE == merchantOrder.getStatus()) {
                        Product product = merchantProductRepository.findByIdAndMerchantIdAndMallId(merchantOrderItem.getProductId(), merchantOrderItem.getMerchantId(), merchantOrderItem.getMallId());
                        if (product.getDateDisabled() != null) {
                            if (product.getDateDisabled().getTime() < new Date().getTime()) {
                                jsonResult.remind("此服务产品已经过期,不能兑换",log);
                                return;
                            }
                        }
                        if (merchantOrderItem == null) {
                            jsonResult.remind("此订单有误,请联系客户人员",log);
                            return;
                        }

                        if (merchantOrderItem.getBuyCount() == merchantOrderItem.getVerifyCount()) {
                            jsonResult.remind("订单数量不足",log);
                            return;
                        }
                        if (ProductMerchantStoreType.PART == product.getProductMerchantStoreType()) {
                            List<ProductMerchantStores> merchantStoresList = productMerchantStoresRepository.findByProductIdAndMerchantId(product.getId(), userInfoDto.merchant.getId());
                            List<Long> storeIds = merchantStoresList.stream().map(ProductMerchantStores::getMerchantStoreId).collect(Collectors.toList());
                            if (!storeIds.contains(dto.getMerchantStoreId())) {
                                jsonResult.remind("此兑换码不能在本店兑换",log);
                                return;
                            }
                        }

                        //服务核销结算
                        if (mallOrder.getGiftId() != null) {
                            fundService.giftPacketVerify(mallOrder, merchantOrder, customerProductOrder.getUseNum());
                        } else {
                            fundService.serviceVerify(mallOrder, merchantOrder, customerProductOrder.getUseNum(),false);
                        }
                    }
                    //记录核销记录
                    MerchantOrderVerification orderVerification = verificationHelper.merchantOrderVerificationSave(merchantOrder, merchantOrderItem, customerProductOrder.getUseNum(), customerProductOrder.getVerifyCode(), customerProductOrder.getCustomerId(), merchantOrderItem.getLogoUrl(), merchantStore.getName(), OrderVerificationWay.KEY_IN, merchantOrder.getMerchantRole());
                    merchantOrderVerificationRepository.save(orderVerification);
                    //记录分销商核销记录
                    if (merchantOrderItem.getMerchantRole() == MerchantOrderMerchantRole.SUPPLIER) {
                        MerchantOrder marketOrder = merchantOrderRepository.findByMarketOrderNumAndMerchantRole(merchantOrder.getMarketOrderNum(), MerchantOrderMerchantRole.DISTRIBUTOR);
                        List<MerchantOrderItem> orderItemList = merchantOrderItemRepository.findByMerchantOrderIdAndMerchantId(marketOrder.getId(), marketOrder.getMerchantId());
                        MerchantOrderVerification verification = verificationHelper.merchantOrderVerificationSave(marketOrder, orderItemList.get(0), customerProductOrder.getUseNum(), customerProductOrder.getVerifyCode(), customerProductOrder.getCustomerId(), merchantOrderItem.getLogoUrl(), merchantStore.getName(), OrderVerificationWay.KEY_IN, marketOrder.getMerchantRole());
                        merchantOrderVerificationRepository.save(verification);
                    }
                    //产品事件记录
                    productEventHelper.productEventSave(merchantOrder, merchantOrderItem, customerProductOrder.getUseNum(), ProductEventType.VERIFIED);
                }

                if (OrderType.GOODS == merchantOrder.getOrderType()) {
                    if (OrderStatus.WAIT_SHOP_PICKUP != merchantOrder.getStatus()) {
                        jsonResult.remind("订单还没完成支付",log);
                        return;
                    }
                    if (!Objects.equals(dto.getMerchantStoreId(), merchantOrder.getMerchantStoreId())) {
                        jsonResult.remind("此兑换码不能在本店兑换",log);
                        return;
                    }
                    for (MerchantOrderItem orderItem : merchantOrderItemList) {
                        //记录核销记录
                        MerchantOrderVerification orderVerification = verificationHelper.merchantOrderVerificationSave(merchantOrder, orderItem, orderItem.getBuyCount(), customerProductOrder.getVerifyCode(), customerProductOrder.getCustomerId(), orderItem.getLogoUrl(), merchantStore.getName(), OrderVerificationWay.KEY_IN, merchantOrder.getMerchantRole());
                        orderVerification = merchantOrderVerificationRepository.save(orderVerification);
//                        log.info("======================>orderVerification:{}", orderVerification);
                        //记录分销商核销记录
                        if (orderItem.getMerchantRole() == MerchantOrderMerchantRole.SUPPLIER) {
                            MerchantOrder marketOrder = merchantOrderRepository.findByMarketOrderNumAndMerchantRole(merchantOrder.getMarketOrderNum(), MerchantOrderMerchantRole.DISTRIBUTOR);
//                            log.info("======================>marketOrder:{}", marketOrder);
//                            log.info("======================>orderItem:{}", orderItem);
//                          List<MerchantOrderItem> orderItemList = merchantOrderItemRepository.findByMerchantOrderIdAndMerchantId(marketOrder.getId(), marketOrder.getMerchantId());

                            Long productId = orderItem.getProductId();
                            Product productDistribute = merchantProductRepository.findByMarketIdAndMerchantId(productId, marketOrder.getMerchantId());
//                            log.info("======================>productDistribute:{}", productDistribute);
                            MerchantOrderItem distributorMerchantOrderItem = merchantOrderItemRepository.findByMarketOrderNumAndMerchantRoleAndProductId(orderItem.getMarketOrderNum(), MerchantOrderMerchantRole.DISTRIBUTOR, productDistribute.getId());
                            MerchantOrderVerification verification = verificationHelper.merchantOrderVerificationSave(marketOrder, distributorMerchantOrderItem, distributorMerchantOrderItem.getBuyCount(), customerProductOrder.getVerifyCode(), customerProductOrder.getCustomerId(), orderItem.getLogoUrl(), merchantStore.getName(), OrderVerificationWay.SCAN, marketOrder.getMerchantRole());
                            verification = merchantOrderVerificationRepository.save(verification);


//                            log.info("======================>verification:{}", verification);
                        }
                        //产品事件记录
                        productEventHelper.productEventSave(merchantOrder, orderItem, orderItem.getBuyCount(), ProductEventType.VERIFIED);
                    }
                    //商品订单到店自提核销结算
                    if (mallOrder.getGiftId() != null) {
                        fundService.giftPacketVerify(mallOrder, merchantOrder, null);
                    } else {
                        fundService.productVerify(mallOrder, merchantOrder);
                    }
                }


                customerProductOrder.setStatus(CustomerProductOrderStatus.USED);
                customerProductOrderRepository.save(customerProductOrder);

                //订单事件记录
                orderEventHelper.saveOrderEvent(merchantOrder, OrderEventType.VERIFY_KEY_IN, userInfoDto.merchant.getName(), userInfoDto.merchant.getId());

            }
            if (VerifyType.COUPON == VerifyType.valueOf(dto.getVerifyType())) {
                CustomerCouponWallet customerCouponWallet = customerCouponWalletRepository.findByVerifyCodeAndStatusAndIsDelete(dto.getVerifyCode(), CustomerCouponWalletStatus.TO_USE, Whether.NO);
                if (customerCouponWallet == null) {
                    jsonResult.remind("兑换码 不存在",log);
                    return;
                }

                MerchantCoupon merchantCoupon = merchantCouponRepository.findByIdAndStatus(customerCouponWallet.getCouponId(), MerchantCouponStatus.ISSUED);
                if (merchantCoupon == null) {
                    jsonResult.remind("此兑换码卡卷不存在",log);
                    return;
                }

                if (merchantCoupon.getStatus() == MerchantCouponStatus.EXPIRED) {
                    jsonResult.remind("此优惠券已经过期,不能进行兑换",log);
                    return;
                }

                if (merchantCoupon.getDateDisabled().getTime() < new Date().getTime()) {
                    jsonResult.remind("此优惠券已经过期,不能进行兑换",log);
                    return;
                }

                if (CouponUseScope.ALL_STORE != merchantCoupon.getUseScope() && CouponUseScope.PART_STORE != merchantCoupon.getUseScope()) {
                    jsonResult.remind("卡券" + merchantCoupon.getName() + "不适用于线下门店核销!",log);
                    return;
                }

                if (CouponUseScope.PART_STORE == merchantCoupon.getUseScope()) {
                    List<CouponMerchantStore> merchantStoreList = couponMerchantStoreRepository.findByCouponIdAndIsDelete(merchantCoupon.getId(), Whether.NO);
                    List<Long> storeIds = merchantStoreList.stream().map(CouponMerchantStore::getId).collect(Collectors.toList());
                    if (!storeIds.contains(dto.getMerchantStoreId())) {
                        jsonResult.remind("此兑换码不能在本店兑换",log);
                        return;
                    }
                }

                customerCouponWallet.setStatus(CustomerCouponWalletStatus.USED);
                Customer customer = customerRepository.findByIdAndMallId(customerCouponWallet.getCustomerId(), merchantCoupon.getMallId());
                customerCouponWallet.setCustomerName(customer.getNickName());
                customerCouponWallet.setMerchantStoreName(merchantStore.getName());
                customerCouponWallet.setUseNum(1L);
                customerCouponWallet.setVerificationWay(OrderVerificationWay.KEY_IN);

                customerCouponWalletRepository.save(customerCouponWallet);

                //TODO 卡卷事件记录
            }
        };
        return doing.go(request, log);
    }


}
